import axios from 'axios'

// 获取用户购物车详情信息
export function getUserCartDetail(userId) {
  return axios.get(`/api/cart/detail/${userId}`)
}

// 添加商品到购物车
export function addToCart(data) {
  return axios.post('/api/cart/add', data)
}

// 获取购物车项
export function getCartItem(id) {
  return axios.get(`/api/cart/${id}`)
}

// 根据用户ID和菜品ID获取购物车项
export function getCartItemByUserAndFood(userId, foodId) {
  return axios.get(`/api/cart/user/${userId}/food/${foodId}`)
}

// 更新购物车商品数量
export function updateCartItemQuantity(id, quantity, userId) {
  return axios.put(`/api/cart/${id}/quantity?userId=${userId}&quantity=${quantity}`)
}

// 删除购物车项
export function deleteCartItem(id, userId) {
  return axios.delete(`/api/cart/${id}?userId=${userId}`)
}

// 获取用户购物车列表
export function getUserCart(userId) {
  return axios.get(`/api/cart/user/${userId}`)
}

// 根据用户ID和商家ID获取购物车列表
export function getUserCartByMerchant(userId, merchantId) {
  return axios.get(`/api/cart/user/${userId}/merchant/${merchantId}`)
}

// 清空用户购物车
export function clearUserCart(userId) {
  return axios.delete(`/api/cart/clear/${userId}`)
}

// 清空用户在指定商家的购物车
export function clearUserCartByMerchant(userId, merchantId) {
  return axios.delete(`/api/cart/clear/${userId}/${merchantId}`)
}

// 获取购物车中商品总数
export function getCartItemCount(userId) {
  return axios.get(`/api/cart/count/${userId}`)
}

// 批量删除购物车项
export function batchDeleteCartItems(ids, userId) {
  return axios.delete('/api/cart/batch', { data: { ids, userId } })
}

// 更新购物车项备注
export function updateCartItemRemark(id, remark, userId) {
  return axios.put(`/api/cart/${id}/remark?userId=${userId}`, { remark })
} 